package org.chen.spring.aop.factory;

import org.chen.spring.aop.annotation.Aspect;
import org.chen.spring.core.factory.BeanFactory;
import org.chen.spring.core.factory.ScanBean;

import java.lang.annotation.Annotation;
import java.util.List;

/**
 * 切面扫描类
 *
 * @author Chen
 * @since 2023/6/8 15:55
 */
public class AspectScanBean extends ScanBean {
    public AspectScanBean(List<String> componentScan) {
        super(componentScan);
    }

    public AspectScanBean(String componentScan) {
        super(componentScan);
    }

    @Override
    protected void assembleBeanDefinition(Class<?> bean, Annotation annotation) {
        Class<? extends Annotation> annotationType = annotation.annotationType();
        if (annotationType == Aspect.class) {
            AspectFactory.registerAspect(bean);
            BeanFactory.registerBean(bean.getSimpleName(), bean);
        }
    }
}
